/**
 * @description 更新浏览量
 */
const chalk = require("chalk");
const db = require("../../db/index");

exports.updateViews = (dbName, id) => {
  return new Promise((resolve, reject) => {
    let sql = `select views from ${dbName} where id=` + id;
    db.query(sql, (err, result) => {
      if (err) return reject(err);
      let sql =
        `update ${dbName} set views=${Number(result[0].views) + 1} where id=` +
        id;
      db.query(sql, (err, result) => {
        if (err) return reject(err);
        resolve(true);
      });
    });
  }).catch((err) => {
    console.log(chalk.red(err));
  });
};
